package com.example.demo.utils;

import com.auth0.jwt.interfaces.Claim;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class ToKenVer {
    public static int Verification(String token){
        try {
            Map<String, Claim> map = null;
            map = JwtUtil.verifyToken(token);
            for (Map.Entry<String, Claim> entry : map.entrySet()){
                if (entry.getValue().asString() != null){
                    System.out.println("..........................");
                    System.out.println(entry.getKey() + "===" + entry.getValue().asString());
                    System.out.println("..........................");
                }else {
                    System.out.println("..........................");
                    System.out.println(entry.getKey() + "===" + entry.getValue().asDate());
                    System.out.println("..........................");
                }
            }
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }

    }
    public static int Vctoken(){
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        String token=request.getHeader("token");
        try {
            Map<String, Claim> map = null;
            map = JwtUtil.verifyToken(token);
            for (Map.Entry<String, Claim> entry : map.entrySet()){
                if (entry.getValue().asString() != null){
                    System.out.println("..........................");
                    System.out.println(entry.getKey() + "===" + entry.getValue().asString());
                    System.out.println("..........................");
                }else {
                    System.out.println("..........................");
                    System.out.println(entry.getKey() + "===" + entry.getValue().asDate());
                    System.out.println("..........................");
                }
            }
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }


}

